import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;


public class TextManager {

	private ArrayList<String> TextList = new ArrayList<String>();
	
	//to read the file and save texts in it to TextList array.
	public TextManager(String textname) throws IOException
	{
		FileReader TextReader = new FileReader(textname+".txt");
		BufferedReader TextBufferedReader = new BufferedReader(TextReader);
		
		String line = null;
		while ((line = TextBufferedReader.readLine()) != null) {
			StringTokenizer st = new StringTokenizer(line);
			TextList.add(st.nextToken());
		}
		
		TextReader.close();
		TextBufferedReader.close();
		
	}
	
	//add new String to TextList array
	public void addText(String addstring)
	{
		TextList.add(addstring);
	}
	
	//save TextList array in the .txt
	public void saveText(String textname) throws IOException
	{
		FileWriter textWriter = new FileWriter(textname+".txt");
		
		for(int i = 0; i<TextList.size();i++)
		{
			textWriter.write(TextList.get(i));
			textWriter.write("\r\n");
		}
		
		textWriter.close();
	}

	public ArrayList<String> getTextList() {
		return TextList;
	}

	public void setTextList(ArrayList<String> textList) {
		this.TextList = textList;
	}
	
	public void add(String string)
	{
		this.TextList.add(string);
	}
	
}
